/*
 * LotOT.java
 *
 * $Id: LotOT.java,v 1.2 2009-10-01 10:17:45 mario Exp $
 */
package org.ceteca.explica.core.warehouse;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.partners.AddressOT;
import org.ceteca.explica.core.util.Converter;

/**
 * Store class to hold the data of a warehouse.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of warehouse data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class LotOT extends BaseVO implements Serializable {
	/**
	 * Internal id of the lot.
	 */
	private long idLot;
	/**
	 * Description of the lot.
	 */
	private String description;
	/**
	 * Lot number of the lot.
	 */
	private String number;
	/**
	 * Creation date of the lot.
	 */
	private Date creationDate;
	/**
	 * Expiration date of the lot.
	 */
	private Date expirationDate;
	/**
	 * Initial quantity of products belonging to the lot.
	 */
	private BigDecimal quantity;
	/**
	 * Product of the lot.
	 */
	private ProductOT product;
	/**
	 * Internal id of the product (Foreign key).
	 */
	private long idProduct;

	/**
	 * Version of the product used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	
	private static final long serialVersionUID = 10000003;
	
	
	public long getIdLot() {
		return idLot;
	}
	public void setIdLot(long idLot) {
		this.idLot = idLot;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	public Date getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	public Date getExpirationDate() {
		return expirationDate;
	}
	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}
	public BigDecimal getQuantity() {
		return quantity;
	}
	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}
	public ProductOT getProduct() {
		return product;
	}
	public void setProduct(ProductOT product) {
		this.product = product;
	}
	public Integer getVersion() {
		return version;
	}
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * Implementation of the equals method provided by the serializable interface.
	 */
	public boolean equals(Object other) {
        if (this == other) 
        	return true;
        if ( !(other instanceof LotOT) ) 
        	return false;

        final LotOT w = (LotOT) other;

        if ( w.getDescription() == null )
        	return this.getDescription() == null;
        else if ( !w.getDescription().equals( this.getDescription())) 
        	return false;
        
        if ( w.getProduct() == null )
        	return this.getProduct() == null;
        else if ( !w.getProduct().equals( this.getProduct()))
        	return false;

        return true;
    }

	/**
	 * Implementation of the hashCode method provided by the serializable interface.
	 */
    public int hashCode() {
        int result;
        if (this == null || this.getDescription() == null)
        	result = 0;
        else
        	result = this.getDescription().hashCode() + this.getProduct().hashCode();
        return result;
    }
    
	/**
	 * Implementation of the toString() method to show the data of the ProductOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idLot);
			result.append("\nDESCRIPTION: ");
			result.append(this.description);
			result.append("\nNUMBER: ");
			result.append(this.number);
			result.append("\nPRODUCT: ");
			result.append(this.product);
			result.append("\nCREATION DATE: ");
			result.append(Converter.getInstance().toString(this.creationDate));
			result.append("\nEXPIRATION DATE: ");
			result.append(Converter.getInstance().toString(this.expirationDate));
			result.append("\n: QUANTITY");
			result.append(this.quantity);
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting LotOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idLot == id.longValue();
	}

	@Override
	public String getEntityId() {
		return InterfaceWarehouse.EXPLICA_ENTITY_WAREHOUSE_ID;
	}
	@Override
	public long getInternalId() {
		return this.getIdLot();
	}
	@Override
	public String getInternalValue() {
		return this.description;
	}
	
	public String getProductName() {
		if (this.product != null)
			return this.product.getDescription();
		else
			return "";
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: LotOT.java,v 1.2 2009-10-01 10:17:45 mario Exp $";
	}
}
